package com.pf.export;

import com.google.common.collect.Lists;
import com.pf.utils.ExportExcelUtils;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.File;
import java.io.FileOutputStream;
import java.util.List;

/**
 * 下拉多选
 *
 * @author PanFei
 * @version 1.0.0
 * @createTime 2023/3/6 21:12
 */
public class DropDownMultipleListDemo {

    public static void main(String[] args) throws Exception {
        createDropDownMultipleList();
    }

    /**
     * 创建下拉多选
     * <p>
     * 下拉多选设置下拉列表和单选一样，区别是在excel中要设置下拉多选的VB函数
     */
    private static void createDropDownMultipleList() throws Exception {
        String property = System.getProperty("user.dir");
        String filePath = property + "/basic-demo/src/main/resources/DropDownMultipleListTemplate.xlsm";
        File file = new File(filePath);
        XSSFWorkbook workbook = new XSSFWorkbook(file);
        XSSFSheet sheet = workbook.getSheetAt(0);
        workbook.setSheetName(0, "下拉多选");
        // 创建表头
        XSSFRow headRow = sheet.createRow(0);
        XSSFCell headCell = headRow.createCell(0);
        headCell.setCellValue("球类");
        headCell.setCellStyle(ExportExcelUtils.getHeadCellStyle(workbook));
        // 创建表数据
        XSSFRow dataRow = sheet.createRow(1);
        XSSFCell dataCell = dataRow.createCell(0);
        dataCell.setCellValue("篮球");
        dataCell.setCellStyle(ExportExcelUtils.getDataCellStyle(workbook));

        // 设置下拉列表
        List<String> optionList = Lists.newArrayList("篮球", "足球", "排球");
        ExportExcelUtils.createBoundedDropDownList(sheet, 0, optionList);

        workbook.write(new FileOutputStream("D:/test/dropDownMultipleList.xlsm"));
        System.out.println(">>>> 导出成功...");
    }
}
